package cn.keniykey.mc.viewlibrary.packet;

import javax.annotation.Nullable;

import org.bukkit.entity.Player;

import cn.keniykey.mc.viewlibrary.ViewLibraryMain;
import cn.keniykey.mc.viewlibrary.packet.api.AbPacket;
import cn.keniykey.mc.viewlibrary.packet.api.IPacketDispatch;
import cn.keniykey.mc.viewlibrary.reflection.ReflectionUtil;
import cn.keniykey.mc.viewlibrary.toolkit.VerAnalysisUtil;

public abstract class AbPacketUtil {
	protected AbPacketUtil(){}
	
	private static AbPacketUtil util;
	
	static{
		if(ReflectionUtil.isForgeServer()) {
			util = new PacketUtilForgeV1_12_1();
		}else {
			if(VerAnalysisUtil.isAfter("1.17")) {
				util = new PacketUtilV1_17_1();
			}else {
				util = new PacketUtilV1_16_3();
			}
		}
		ViewLibraryMain.getPlugin().getLogger().info("AbContainerUtil调用: " + util.getClass().getSimpleName());
	}
	
	public static AbPacketUtil getUtil() {
		return util;
	}
	/**
	 * 注意！AbPacketDispatch里面的dispatchPacket靠这个方法实现，不要套娃！
	 */
	public abstract void dispatchPacket(Player player,IPacketDispatch packet,boolean cache);
	/**
	 * 根据接收到的nmspacket转为AbPacket，若不存在则返回null
	 * 当packet属于windowpacket时，会判断windowid是否一致，否则返回null
	 */
	@Nullable
	public abstract AbPacket coverPacket(Object nmspacket,int windowid);
}